"use strict";

const CopyWebpackPlugin = require("copy-webpack-plugin");
const path = require("path");

const config = {
    entry: ["./src/mxgraph-factory.ts"],
    module: {
        rules: [
            {
                enforce: "pre",
                loader: "tslint-loader",
                options: {
                    emitErrors: true,
                    failOnHint: true,
                    typeCheck: true,
                },
                test: /\.ts$/,
            },
            {
                loader: "ts-loader",
                test: /\.ts$/,
            },
            {
                test: /mxClient\.js$/,
                options: {
                    type: 'commonjs',
                    exports: [
                        "mxAbstractCanvas2D",
                        "mxActor",
                        "mxAnimation",
                        "mxArrow",
                        "mxArrowConnector",
                        "mxAutoSaveManager",
                        "mxCell",
                        "mxCellAttributeChange",
                        "mxCellEditor",
                        "mxCellHighlight",
                        "mxCellMarker",
                        "mxCellOverlay",
                        "mxCellRenderer",
                        "mxCellState",
                        "mxCellStatePreview",
                        "mxCellTracker",
                        "mxChildChange",
                        "mxCircleLayout",
                        "mxClient",
                        "mxClipboard",
                        "mxCloud",
                        "mxCodec",
                        "mxCodecRegistry",
                        "mxCollapseChange",
                        "mxCompactTreeLayout",
                        "mxCompositeLayout",
                        "mxConnectionConstraint",
                        "mxConnectionHandler",
                        "mxConnector",
                        "mxConstraintHandler",
                        "mxConstants",
                        "mxCoordinateAssignment",
                        "mxCurrentRootChange",
                        "mxCylinder",
                        "mxDefaultKeyHandler",
                        "mxDefaultPopupMenu",
                        "mxDefaultToolbar",
                        "mxDictionary",
                        "mxDivResizer",
                        "mxDoubleEllipse",
                        "mxDragSource",
                        "mxEdgeHandler",
                        "mxEdgeLabelLayout",
                        "mxEdgeSegmentHandler",
                        "mxEdgeStyle",
                        "mxPerimeter",
                        "mxEditor",
                        "mxElbowEdgeHandler",
                        "mxEllipse",
                        "mxEvent",
                        "mxEventObject",
                        "mxEventSource",
                        "mxFastOrganicLayout",
                        "mxForm",
                        "mxGeometry",
                        "mxGeometryChange",
                        "mxGraph",
                        "mxGraphAbstractHierarchyCell",
                        "mxGraphHandler",
                        "mxGraphHierarchyEdge",
                        "mxGraphHierarchyModel",
                        "mxGraphHierarchyNode",
                        "mxGraphLayout",
                        "mxGraphModel",
                        "mxGraphSelectionModel",
                        "mxGraphView",
                        "mxGuide",
                        "mxHandle",
                        "mxHexagon",
                        "mxHierarchicalLayout",
                        "mxHierarchicalLayoutStage",
                        "mxImage",
                        "mxImageBundle",
                        "mxImageExport",
                        "mxImageShape",
                        "mxKeyHandler",
                        "mxLabel",
                        "mxLayoutManager",
                        "mxLine",
                        "mxLog",
                        "mxMedianHybridCrossingReduction",
                        "mxMinimumCycleRemover",
                        "mxMorphing",
                        "mxMouseEvent",
                        "mxMultiplicity",
                        "mxObjectCodec",
                        "mxOutline",
                        "mxPanningHandler",
                        "mxPanningManager",
                        "mxParallelEdgeLayout",
                        "mxPartitionLayout",
                        "mxPoint",
                        "mxPolyline",
                        "mxPopupMenu",
                        "mxPopupMenuHandler",
                        "mxPrintPreview",
                        "mxRadialTreeLayout",
                        "mxRectangle",
                        "mxRectangleShape",
                        "mxRhombus",
                        "mxRootChange",
                        "mxRubberband",
                        "mxSelectionCellsHandler",
                        "mxSelectionChange",
                        "mxShape",
                        "mxStackLayout",
                        "mxStencil",
                        "mxStencilRegistry",
                        "mxStyleChange",
                        "mxStyleRegistry",
                        "mxStylesheet",
                        "mxSvgCanvas2D",
                        "mxSwimlane",
                        "mxSwimlaneLayout",
                        "mxSwimlaneManager",
                        "mxSwimlaneModel",
                        "mxSwimlaneOrdering",
                        "mxTemporaryCellStates",
                        "mxTerminalChange",
                        "mxText",
                        "mxToolbar",
                        "mxTooltipHandler",
                        "mxTriangle",
                        "mxUndoableEdit",
                        "mxUndoManager",
                        "mxUtils",
                        "mxValueChange",
                        "mxVertexHandler",
                        "mxVisibleChange",
                        "mxWindow",
                        "mxXmlCanvas2D",
                        "mxXmlRequest",
                    ],
                },
                loader: "exports-loader",
            },
        ],
    },
    output: {
        library: "mxgraph-factory",
        libraryTarget: "commonjs2",
        path: path.resolve("dist"),
    },
    performance: {
        hints: false,
    },
    plugins: [
        new CopyWebpackPlugin({
            patterns: [
                {
                    context: "src",
                    from: "*.d.ts",
                },
            ],
        }),
    ],
    resolve: {
        extensions: [".js", ".ts"],
        modules: ["./node_modules", "./src"],
    },
};

module.exports = [
    {
        ...config,
        devtool: "none",
        mode: "development",
        output: {
            ...config.output,
            filename: "mxgraph-factory.js",
        },
    },
    {
        ...config,
        mode: "production",
        output: {
            ...config.output,
            filename: "mxgraph-factory.min.js",
        },
    },
];
